home *** CD-ROM | disk | FTP | other *** search
- /*
- ** Apple Macintosh Developer Technical Support
- **
- ** Program: MacShell
- ** File: window2.c
- ** Written by: Eric Soldan
- **
- ** Copyright © 1990-1991 Apple Computer, Inc.
- ** All rights reserved.
- */
-
-
-
- /*****************************************************************************/
-
-
-
- #include "MacShell.h" /* Get the MacShell includes/typedefs, etc. */
- #include "MacShellCommon.h" /* Get the stuff in common with rez. */
- #include "MacShell.protos" /* Get the prototypes for MacShell. */
-
- #ifndef __CTLHANDLER__
- #include "CtlHandler.h"
- #endif
-
- #ifndef __ERRORS__
- #include <Errors.h>
- #endif
-
- #ifndef __FONTS__
- #include <Fonts.h>
- #endif
-
- #ifndef __LISTCONTROL__
- #include "ListControl.h"
- #endif
-
- #ifndef __RESOURCES__
- #include <Resources.h>
- #endif
-
- #ifndef __TEXTEDITCONTROL__
- #include "TextEditControl.h"
- #endif
-
- #ifndef __TOOLUTILS__
- #include <ToolUtils.h>
- #endif
-
- #ifdef THINK_C
- #include "Utilities.h"
- #else
- #ifndef __UTILITIES__
- #include <Utilities.h>
- #endif
- #endif
-
-
-
- /*****************************************************************************/
-
-
-
- extern short gPrintPage; /* Non-zero means we are printing. */
-
-
-
- /*****************************************************************************/
- /*****************************************************************************/
-
-
-
- /* This function adds the application's controls to a window. */
-
- #pragma segment Window
- OSErr InitContent(FileRecHndl frHndl, WindowPtr window)
- {
- #if MACSHELL_VERSION
-
- WindowPtr oldPort;
- short i, mode;
- Rect ctlRect, brdrRect, viewRect, destRect;
- TEHandle teHndl, textBox[2];
- Handle text;
- OSErr err;
-
- err = noErr;
-
- GetPort(&oldPort);
- SetPort(window);
-
- for (i = 0; i < 2; ++i) {
- ctlRect = window->portRect;
- --ctlRect.top;
- --ctlRect.left;
- ctlRect.right -= 14;
- ctlRect.bottom = ctlRect.top + (ctlRect.bottom - ctlRect.top + 1) / 2;
- if (i) {
- ctlRect.top = ctlRect.bottom - 1;
- ctlRect.bottom = window->portRect.bottom + 1;
- }
- brdrRect = ctlRect;
- viewRect = ctlRect;
- InsetRect(&viewRect, 4, 4);
- destRect = viewRect;
- destRect.right -= 2; /* This fixes a TextEdit problem where the
- ** view has to be a little outside the dest on
- ** the right, or else characters are clipped. */
-
- mode = i ? (cteVScrollLessGrow | cteActive) : (cteReadOnly + cteVScroll);
- CTENew(rTECtl, /* View ctl ResID used for TextEdit control. */
- window, /* Window to hold TERecord. */
- &teHndl, /* Return handle for TERecord. */
- &ctlRect, /* Rect for view control. */
- &destRect, /* destRect for TERecord. */
- &viewRect, /* viewRect for TERecord. */
- &brdrRect, /* Used to frame a border. */
- 32000, /* Maximum TextEdit document length. */
- mode /* Read-only or read-write, vert scroll, grow box. */
- );
- if (!(textBox[i] = teHndl)) err = memFullErr;
- }
- (*frHndl)->doc.inBox = textBox[0];
- (*frHndl)->doc.outBox = textBox[1];
-
- if (text = (*frHndl)->doc.textHndl) {
- text = CTESwapText(textBox[1], text, false);
- DisposHandle(text);
- (*frHndl)->doc.textHndl = nil;
- }
-
- SetPort(oldPort);
- return(err);
-
- #else
- #pragma unused (frHndl, window)
- return(noErr);
- #endif
-
- }
-
-
-
- /*****************************************************************************/
-
-
-
- /* Image the document into the current port. */
-
- #pragma segment Window
- void ImageDocument(FileRecHndl frHndl)
- {
- #if MACSHELL_VERSION
-
- WindowPtr thePort;
- Rect rct, theInk;
- TEHandle te;
- short pageCol;
- static short taskOffset, taskNum;
-
- GetPort(&thePort);
-
- if (!gPrintPage) { /* If not printing... */
- DoDrawControls(thePort, false); /* Draw the content controls. */
- }
- else {
-
- if (gPrintPage == 1) taskOffset = taskNum = 0;
-
- theInk = thePort->portRect;
- InsetRect(&theInk, 4, 4); /* Just so no characters get clipped. */
-
- pageCol = 0;
- for (rct = theInk; taskNum < 2;) {
- te = (taskNum) ? (*frHndl)->doc.outBox : (*frHndl)->doc.inBox;
- CTEPrint(te, &taskOffset, &rct);
- if (taskOffset != -1) return; /* Text went to bottom of page. */
- taskOffset = 0; /* Done with this TextEdit record. */
- ++taskNum;
- rct.top = rct.bottom + 20;
- rct.bottom = theInk.bottom;
- if (rct.top + 20 >= rct.bottom) return;
- /* No page left or not enough to bother with. */
- }
- gPrintPage = 0;
- }
-
- #else
- #pragma unused (frHndl)
- #endif
-
- }
-
-
-
- /*****************************************************************************/
-
-
-
- /* Resize application specific content (Called by ResizeWindow). */
-
- #pragma segment Window
- void ResizeContent(WindowPtr window, short oldh, short oldv)
- {
- #if MACSHELL_VERSION
- #pragma unused (oldh, oldv)
-
- FileRecHndl frHndl;
- WindowPtr oldPort;
- short i;
- Rect rct;
- TEHandle te;
-
- if (!window) return;
-
- frHndl = (FileRecHndl)GetWRefCon(window);
- oldPort = SetFilePort(frHndl);
-
- for (i = 0; i < 2; ++i) {
- rct = window->portRect;
- --rct.top;
- --rct.left;
- rct.right -= 14;
- rct.bottom = rct.top + (rct.bottom - rct.top + 1) / 2;
- if (i) {
- rct.top = rct.bottom - 1;
- rct.bottom = window->portRect.bottom + 1;
- }
-
- te = (i) ? (*frHndl)->doc.outBox : (*frHndl)->doc.inBox;
- CTEMove(te, rct.left, rct.top);
- CTESize(te, rct.right - rct.left, rct.bottom - rct.top, true);
- }
-
- SetPort(oldPort);
-
- #else
- #pragma unused (window, oldh, oldv)
- #endif
-
- }
-
-
-
- /*****************************************************************************/
-
-
-
- /* Draw application specific content (Called by DoDrawFrame). */
-
- #pragma segment Window
- void DrawFrame(FileRecHndl frHndl, WindowPtr window)
- {
- #pragma unused (frHndl, window)
- }
-
-
-
- /*****************************************************************************/
-
-
-
- /* Draw application specific frame area (Called by DoCalcFrameRgn). */
-
- #pragma segment Window
- void CalcFrameRgn(FileRecHndl frHndl, WindowPtr window, RgnHandle rgn)
- {
- #pragma unused (frHndl, window, rgn)
- }
-
-
-
- /*****************************************************************************/
-
-
-
- /* This is called when a mouse-down event occurs in the content of a window.
- ** Other applications might want to call FindControl, TEClick, etc., to
- ** further process the click.
- */
-
- #pragma segment Window
- void ContentClick(WindowPtr window, EventRecord *event)
- {
- FileRecHndl frHndl;
- ControlHandle ctl;
- short dblClick;
-
- if (!IsAppWindow(window)) return;
-
- SetPort(window);
-
- if (IsCtlEvent(window, event, &ctl, &dblClick)) return;
-
- frHndl = (FileRecHndl)GetWRefCon(window);
- if ((*frHndl)->fileState.readOnly) return;
- /* Don't allow changes if read-only. */
- }
-
-
-
- /*****************************************************************************/
-
-
-
- /* This is called when a key event occurs and it is determined that it isn't
- ** a menu key.
- */
-
- #pragma segment Window
- void ContentKey(WindowPtr window, EventRecord *event)
- {
- #if MACSHELL_VERSION
- short ctlNum, action;
- ControlHandle ctl;
- #endif
-
- #if MACSHELL_VERSION
- if ((event->message & charCodeMask) == 0x03) {
- SendMessage((FileRecHndl)GetWRefCon(window), kTextMssg);
- return;
- }
- ctlNum = IsCtlEvent(window, event, &ctl, &action);
- if (ctlNum == 2) {
- if (action) {
- SetWindowDirty(window);
- AdjustMenus(); /* Avoid unnecessary DoCursor() and speed */
- } /* up TextEdit entry. */
- return;
- }
- #endif
-
- }
-
-
-
-